const { exec } = require('../db/index')

class UserServer {

  async index() {
    let data = await exec('select * from users');
    return { data }
  }

  async page(ctx, next) {
    const { page = 0, size = 5 } = ctx.query;
    // 查询分页总数
    let total = await exec('select count(*) as num from users')
    let data = await exec(`select * from users limit ${size} offset ${page * size}`);
    return { total, data }
  }

  async login(ctx) {
    console.log(ctx.request.body, 'body')
    const { username, password } = ctx.request.body;
    let data = await exec(`select * from users where username='${username}' and password='${password}';`)
    return data;
  }

}

module.exports = new UserServer